
// UstavSRDlg.h : header file
//

#pragma once

#include "SerialMFC.h"

#include "UR_GOTO.h"
#include "UR_LIGHTS.h"
#include "US_DATA.h"
#include "US_STATUS.h"
#include "afxwin.h"

// CUstavSRDlg dialog
class CUstavSRDlg : public CDialogEx
{
// Construction
public:
    CUstavSRDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
    enum { IDD = IDD_USTAVSR_DIALOG };

    protected:
    virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
    HICON m_hIcon;

    CSerialMFC m_serialPort;
    USData m_UsData;
    USStatus m_UsStatus;
	URLights m_UrLights;
	URGoto m_UrGoto;

    CMap<CString, LPCTSTR, CSerial::EParity, CSerial::EParity> m_parityMap;
    CMap<CString, LPCTSTR, CSerial::EStopBits, CSerial::EStopBits> m_stopBitsMap;
    CMap<CString, LPCTSTR, CSerial::EHandshake, CSerial::EHandshake> m_flowControlMap;

    // Generated message map functions
    virtual BOOL OnInitDialog();
    //afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    DECLARE_MESSAGE_MAP()

    void LogMessage(LPCTSTR pszText);

    LONG OpenSerialPort();
    LONG CloseSerialPort();

    void InitSerialControls();

    void EnableSerialControls(BOOL enable=TRUE);
    void EnableSendButtons(BOOL enable=TRUE);
    void EnableModeControlsGroup(BOOL enable=TRUE);
    void EnableNetworkControlsGroup(BOOL enable=TRUE);
    void EnableRouterControlsGroup(BOOL enable=TRUE);
    void EnableServerControlsGroup(BOOL enable=TRUE);
    
public:
    int m_yaw;
    int m_pitch;
    int m_roll;
    int m_heading;
    double m_latitude;
    double m_longitude;
    float m_altitude;
    float m_airSpeed;
    float m_groundSpeed;
    int m_consumption;
    int m_batteryLife;
    int m_health;

    // Serial port controls
    CComboBox m_cb_port;
    CComboBox m_cb_baud;
    CComboBox m_cb_parity;
    CComboBox m_cb_dataBits;
    CComboBox m_cb_stopBits;
    CComboBox m_cb_flowControl;
    CButton m_b_openClosePort;

    // Sending controls
    CButton m_b_sendData;
    CButton m_b_sendStatus;
    CButton m_b_sendGoto;
    CButton m_b_sendLights;
    
    CEdit m_logBox;
    
    afx_msg void OnBnClickedButtonOpenClosePort();
    afx_msg void OnBnClickedButtonSendData();
    afx_msg void OnBnClickedButtonSendStatus();  
    afx_msg void OnBnClickedRadioModeServer();
    afx_msg void OnBnClickedRadioModeRouter();

    afx_msg LRESULT OnSerialMsg (WPARAM wParam, LPARAM lParam);

    void ReadFromSerial();
    void WriteToSerial(const char* str, size_t size);
};